//
//  BWStatuesCellMargin.swift
//  weibo
//
//  Created by libowen on 16/5/24.
//  Copyright © 2016年 libowen. All rights reserved.
//

import UIKit
import SnapKit
let StatusCellMargin: CGFloat = 8
class BWStatuesCellMargin: UIView {
    var status: BWStatus? {
        didSet {
            let url = NSURL(string: status?.user?.profile_image_url ?? "")
            headIcon.sd_setImageWithURL(url)
            nameLable.text = status?.user?.name
            timeLable.text = status?.created_at
            sourceLable.text = status?.source
            contentLable.text = status?.text
            if status?.user?.verified == 1 {
                verifiedImageView.hidden = false
            } else {
                verifiedImageView.hidden = true
            }
            if status?.user?.mbrank > 0 && status?.user?.mbrank < 7
            {
                let image = UIImage(named: "common_icon_membership_level\(status?.user?.mbrank ?? 0)")
                mbrankImageView.image = image
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.yellowColor()
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        addSubview(headIcon)
        addSubview(verifiedImageView)
        addSubview(nameLable)
        addSubview(mbrankImageView)
        addSubview(timeLable)
        addSubview(sourceLable)
        addSubview(contentLable)
        
        headIcon.snp_makeConstraints { (make) -> Void in
        make.top.left.equalTo(self).offset(StatusCellMargin)
        make.height.equalTo(40)
        make.width.equalTo(40)
        }
        
        verifiedImageView.snp_makeConstraints { (make) -> Void in
            make.right.bottom.equalTo(headIcon)
        }
        
        nameLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headIcon.snp_top)
            make.left.equalTo(headIcon.snp_right).offset(StatusCellMargin)
        }
        mbrankImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headIcon.snp_right)
            make.left.equalTo(nameLable.snp_right).offset(StatusCellMargin)
        }
        
        timeLable.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(headIcon.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(headIcon.snp_bottom)
        }
        sourceLable.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLable.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(headIcon.snp_bottom)
        }
        contentLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headIcon.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(headIcon.snp_left)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentLable.snp_bottom).offset(StatusCellMargin)
        }
    }
    private lazy var headIcon: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var verifiedImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    private lazy var timeLable: UILabel = UILabel(title: "11 : 11", font: 10, textColor: UIColor.orangeColor())
    private lazy var nameLable: UILabel = UILabel(title: "李博文", font: 14, textColor: UIColor.darkGrayColor())
    private lazy var sourceLable: UILabel = UILabel(title: "呵呵", font: 10, textColor: UIColor.darkGrayColor())
    private lazy var contentLable: UILabel = UILabel(title: "lalalalalalalalalalalaallalaal", font: 14, textColor: UIColor.darkGrayColor(), alignment: .Left)
}

























